﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Sklad1_2.Add.Update;
using Sklad1_2.Data;
using Sklad1_2.Default;

namespace Sklad1_2.Add
{
    public partial class AddFirma : Defaultform
    {
        public AddFirma()
        {
            InitializeComponent();
            Init();
        }
        public override sealed void Init()
        {
            textBox1.Clear();
            ABase.AddItem(comboBox1,"angar");
            ABase.AddItemDBGridView(dataGridView1,Helper.QueryFirma);
            Helper.Hidden(dataGridView1,0,1,2);
            if (comboBox1.SelectedValue == null)
            {
                MessageBox.Show("Заполните данные о Складах");
                Close();
            }
            if (comboBox2.SelectedValue == null)
            {
                MessageBox.Show("Заполните данные о Категориях");
                Close();
            }
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            Type t = typeof(Int32);
            if (comboBox1.SelectedValue.GetType() == t)
            {
                ABase.AddItemCategory(comboBox2, Convert.ToInt32(comboBox1.SelectedValue));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length>0)
            {
                string sklad = Convert.ToString(comboBox1.SelectedValue),
                       category = Convert.ToString(comboBox2.SelectedValue);

                ABase.InsertValueFirma(sklad,category,textBox1.Text);
                Init();
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            data=new List<string>();
            Helper.Db2List(dataGridView1,e,ref data,0,1,2,5);
            UpdateFirma aUpdateFirma=new UpdateFirma(data);
            aUpdateFirma.FormClosed += Bind;
            aUpdateFirma.ShowDialog();
        }
    }
}
